# This file is part of Laivsys. See doc/README_FOR_APP for more information
# and license.
# (C) Sigve Indregard
# $Id: application_form.rb 50 2007-11-30 22:59:41Z sigve.indregard $

class ApplicationForm < ActiveRecord::Base
  STATUS_ACCEPTED=1
  STATUS_PENDING=0
  STATUS_REFUSED=-1

  belongs_to :laiv
  belongs_to :user

  validates_presence_of :user_id, :laiv_id
  validates_associated :user, :laiv
  validates_inclusion_of :status, 
    :in => [STATUS_ACCEPTED, STATUS_PENDING, STATUS_REFUSED],
    :nil => false
  validates_uniqueness_of :user_id, :scope => :laiv_id,
    :message => 'has already applied'

  def status_to_s
    case status
      when STATUS_ACCEPTED
        "Accepted"
      when STATUS_PENDING
        "Pending"
      when STATUS_REFUSED
        "Refused"
      else
        "Unknown"
    end
  end
end
